home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1151.ASC < prev    next >
Text File  |  1992-11-04  |  4KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1151
  9.   VERSION  :  3.1
  10.        OS  :  ALL
  11.      DATE  :  November 4, 1992                         PAGE  :  1/4
  12.  
  13.     TITLE  :  The source code for the new and delete operators.
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.   /*-----------------------------------------------------------------------*
  21.    * filename - new.cpp
  22.    * C++ NEW
  23.    *-----------------------------------------------------------------------*/
  24.  
  25.   /*
  26.    *        C/C++ Run Time Library - Version 5.0
  27.    *
  28.    *        Copyright (c) 1990, 1992 by Borland International
  29.    *        All Rights Reserved.
  30.    *
  31.    */
  32.  
  33.  
  34.   #include <stddef.h>
  35.   #include <stdlib.h>
  36.  
  37.   typedef void (* pvf)();
  38.  
  39.   pvf _new_handler;
  40.  
  41.   pvf set_new_handler(pvf p)
  42.   {
  43.        pvf t = _new_handler;
  44.        _new_handler = p;
  45.        return t;
  46.   }
  47.  
  48.   void *operator new( size_t size )
  49.   {
  50.        void * p;
  51.        size = size ? size : 1;
  52.        while ( (p = malloc(size)) == NULL && _new_handler != NULL)
  53.             _new_handler();
  54.        return p;
  55.   }
  56.  
  57.  
  58.   /*-----------------------------------------------------------------------*
  59.    * filename - newf.cpp
  60.    * C++ NEW
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1151
  75.   VERSION  :  3.1
  76.        OS  :  ALL
  77.      DATE  :  November 4, 1992                         PAGE  :  2/4
  78.  
  79.     TITLE  :  The source code for the new and delete operators.
  80.  
  81.  
  82.  
  83.  
  84.    *-----------------------------------------------------------------------*/
  85.  
  86.   /*
  87.    *        C/C++ Run Time Library - Version 5.0
  88.    *
  89.    *        Copyright (c) 1990, 1992 by Borland International
  90.    *        All Rights Reserved.
  91.    *
  92.    */
  93.  
  94.  
  95.   #include <stddef.h>
  96.   #include <alloc.h>
  97.  
  98.   typedef void (*pvf)();
  99.  
  100.   extern pvf _new_handler;
  101.  
  102.   void far * operator new( unsigned long size )
  103.   {
  104.        void far * p;
  105.        size = size ? size : 1;
  106.        while ( (p = farmalloc(size)) == NULL && _new_handler !=
  107.                 NULL)
  108.             _new_handler();
  109.        return p;
  110.   }
  111.  
  112.  
  113.  
  114.   /*-----------------------------------------------------------------------*
  115.    * filename - del.cpp
  116.    * C++ DELETE
  117.    *-----------------------------------------------------------------------*/
  118.  
  119.   /*
  120.    *      C/C++ Run Time Library - Version 5.0
  121.    *
  122.    *      Copyright (c) 1990, 1992 by Borland International
  123.    *      All Rights Reserved.
  124.    *
  125.    */
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1151
  141.   VERSION  :  3.1
  142.        OS  :  ALL
  143.      DATE  :  November 4, 1992                         PAGE  :  3/4
  144.  
  145.     TITLE  :  The source code for the new and delete operators.
  146.  
  147.  
  148.  
  149.  
  150.   #include <stddef.h>
  151.   #include <stdlib.h>
  152.  
  153.   void operator delete( void _FAR *ptr )
  154.   {
  155.        free(ptr);
  156.   }
  157.  
  158.  
  159.  
  160.   /*-----------------------------------------------------------------------*
  161.    * filename - delf.cpp
  162.    * C++ DELETE
  163.    *-----------------------------------------------------------------------*/
  164.  
  165.   /*
  166.    *        C/C++ Run Time Library - Version 5.0
  167.    *
  168.    *        Copyright (c) 1990, 1992 by Borland International
  169.    *        All Rights Reserved.
  170.    *
  171.    */
  172.  
  173.  
  174.   #include <stddef.h>
  175.   #include <alloc.h>
  176.   #include <dos.h>
  177.  
  178.   #if defined(__TINY__) || defined(__SMALL__) ||
  179.       defined(__MEDIUM__)
  180.   void operator delete( void far *ptr )
  181.   {
  182.        if (FP_SEG(ptr) == _DS)
  183.             free((void *) ptr);
  184.        else
  185.             farfree(ptr);
  186.   }
  187.   #endif
  188.  
  189.  
  190.  
  191.   DISCLAIMER: You have the right to use this technical information
  192.   subject to the terms of the No-Nonsense License Statement that
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1151
  207.   VERSION  :  3.1
  208.        OS  :  ALL
  209.      DATE  :  November 4, 1992                         PAGE  :  4/4
  210.  
  211.     TITLE  :  The source code for the new and delete operators.
  212.  
  213.  
  214.  
  215.  
  216.   you received with the Borland product to which this information
  217.   pertains.
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.